#!/usr/bin/python
# -*- coding: UTF-8 -*-
from datetime import datetime
import re

class FilterData(object):

    def __init__(self,data):
        self.data=data

    def filter_time(self):
        self.data["timestamps"]=self.data["timestamps"].apply(self.__handleTime)
        self.data["user_name"]=self.data["user_name"]=1
        return self.data
    def filter_zan(self):
        self.data["zan_count"]=self.data["zan_count"].apply(self.__handleZan)
        return self.data
    def group_zan(self):
        self.data["type"]=0
        count=list(self.data["type"]).__len__()
        for i in range(count):
            print(i)
            zan=self.data["zan_count"][i]
            if(zan<10):
                self.data["type"][i]=0
            elif(zan>10 and zan <50):
                self.data["type"][i] = 1
            elif (zan>50 and zan <200):
                self.data["type"][i] = 2
            else:
                self.data["type"][i] = 3
        return self.data




    def __handleZan(self,str):
        result=re.compile("\d+").search(str)
        if result:
            return int(result.group(0))
        else:
            return 0



    def __handleTime(self,str):
        time = ""
        try:
            if "年" in str:
                if ":" in str:
                    time_mode = "%Y年%m月%d日 %H:%M"
                    time = datetime.strptime(str, time_mode)
                else:
                    time_mode = "%Y年%m月%d日"
                    time = datetime.strptime(str, time_mode)
            else:
                time_mode = "%m月%d日 %H:%M"
                time = datetime.strptime(str, time_mode)
                print(time.year)
                time_now = datetime.now()
                time = datetime(time_now.year, time.month, time.day, time.hour, time.minute)
        except:
            return datetime.now()
        return time

